import 'package:flutter/material.dart';

/// 单元格，类似ListTile
class TagCell extends StatelessWidget {
  final String title;
  final double titleSize;
  final Widget? icon;
  final Widget? rightIcon;
  final Widget? child;
  final String? desc;
  final void Function()? onTap;
  final double vPadding;
  final double hPadding;
  final double spacing;
  final Color? titleColor;
  final EdgeInsetsGeometry? margin;
  final bool hasBorder;
  final Color? backgroundColor;

  const TagCell({
    Key? key,
    this.title = '',
    this.icon,
    this.desc,
    this.onTap,
    this.vPadding = 10,
    this.hPadding = 10,
    this.spacing = 8,
    this.titleColor,
    this.margin,
    this.child,
    this.titleSize = 14,
    this.rightIcon,
    this.backgroundColor,
    this.hasBorder = true,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    final colorScheme = Theme.of(context).colorScheme;
    return GestureDetector(
      onTap: onTap,
      child: Container(
        color: backgroundColor ?? colorScheme.surface,
        padding: EdgeInsets.symmetric(horizontal: hPadding),
        margin: margin,
        child: Container(
          padding: EdgeInsets.symmetric(vertical: vPadding),
          decoration: hasBorder
              ? BoxDecoration(
                  border: Border(
                    bottom: BorderSide(
                      color: Colors.grey[300]!,
                      width: 0.5,
                    ),
                  ),
                )
              : null,
          child: Row(
            crossAxisAlignment: CrossAxisAlignment.center,
            mainAxisAlignment: MainAxisAlignment.start,
            children: [
              if (icon != null) icon!,
              if (title.isNotEmpty)
                Padding(
                  padding: EdgeInsets.only(right: spacing),
                  child: Text(
                    title,
                    style: TextStyle(
                      fontSize: titleSize,
                      color: titleColor ?? colorScheme.onSurface,
                    ),
                  ),
                ),
              Expanded(child: child ?? const Text('')),
              SizedBox(width: spacing),
              if (desc != null)
                Padding(
                  padding: EdgeInsets.only(
                    right: (rightIcon != null || onTap != null) ? spacing : 0,
                  ),
                  child: Text(
                    desc!,
                    style: Theme.of(context).textTheme.caption,
                  ),
                ),
              if (rightIcon != null) rightIcon!,
              if (rightIcon == null && onTap != null)
                const Icon(
                  Icons.chevron_right,
                  color: Colors.grey,
                ),
            ],
          ),
        ),
      ),
    );
  }
}
